package com.lx.commonlib.utils.ui;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

/**
 * 类说明：Drawable工具类
 * Created by liuxiong on 2020/1/13.
 */
public class DrawableUtil {

    /**
    * 方法说明:  设置图片边界
    * created by liuxiong on 2020/1/13 15:21
    */
    public static void setCompoundDrawables(TextView textView, Drawable leftmDrawable, Drawable topDrawable, Drawable rightDrawable, Drawable bottomDrawable)
    {
        setDrawableBounds(leftmDrawable);
        setDrawableBounds(topDrawable);
        setDrawableBounds(rightDrawable);
        setDrawableBounds(bottomDrawable);
        textView.setCompoundDrawables(leftmDrawable, topDrawable, rightDrawable, bottomDrawable);
    }

    public static void setCompoundDrawables(TextView textView, int resLeftId, int resRightId, int resTopId, int resBottomId)
    {
        Context context = textView.getContext();
        setCompoundDrawables(textView, ResourcesUtil.getDrawable(resLeftId), ResourcesUtil.getDrawable(resRightId), ResourcesUtil.getDrawable( resTopId), ResourcesUtil.getDrawable( resBottomId));
    }

    public static void setDrawableBounds(Drawable drawable)
    {
        if (drawable != null)
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    }


    /**
     * 方法说明:  设置TextView左边的图片
     * created by liuxiong on 2020/1/13 15:21
     */
    public static void setLeftDrawable(TextView textView, Drawable leftDrawable)
    {
        DrawableUtil.setDrawableBounds(leftDrawable);
        textView.setCompoundDrawables(leftDrawable, null, null, null);
    }

    public static void setLeftDrawable(TextView textView, int resId)
    {
        setLeftDrawable(textView, ResourcesUtil.getDrawable( resId));
    }

    /**
     * 方法说明:  设置TextView上边的图片
     * created by liuxiong on 2020/1/13 15:21
     */
    public static void setTopDrawable(TextView textView, Drawable topDrawable)
    {
        DrawableUtil.setDrawableBounds(topDrawable);
        textView.setCompoundDrawables(null, topDrawable, null, null);
    }

    public static void setTopDrawable(TextView textView, int resId)
    {
        setTopDrawable(textView, ResourcesUtil.getDrawable(resId));
    }

    /**
     * 方法说明:  设置TextView右边的图片
     * created by liuxiong on 2020/1/13 15:21
     */
    public static void setRightDrawable(TextView textView, Drawable rightDrawable)
    {
        DrawableUtil.setDrawableBounds(rightDrawable);
        textView.setCompoundDrawables(null, null, rightDrawable, null);
    }

    public static void setRightDrawable(TextView textView, int resId)
    {
        setRightDrawable(textView, ResourcesUtil.getDrawable( resId));
    }

    /**
     * 方法说明:  设置TextView下边的图片
     * created by liuxiong on 2020/1/13 15:21
     */
    public static void setBottomDrawable(TextView textView, Drawable bottomDrawable)
    {
        DrawableUtil.setDrawableBounds(bottomDrawable);
        textView.setCompoundDrawables(null, null, bottomDrawable, null);
    }

    public static void setBottomDrawable(TextView textView, int resId)
    {
        setBottomDrawable(textView, ResourcesUtil.getDrawable( resId));
    }

}
